package com.sls.nzdapplication.httpclient;

import com.alibaba.fastjson.JSONObject;


public class UserUtil {

    private static String LOGINPATH = "/api/auth/signin";

    private static String USERINFO = "/api/sys/user/info";
    /**
     *
     * 参数一：请求Url
     * 参数二：请求的JSON
     * 参数三：请求回调
     */
    public static JSONObject loginPostJsonParams(String url, String jsonParams) {
        JSONObject userinfo = new JSONObject();
        try{
            JSONObject jsonObject = JSONObject.parseObject(OkHttpUtil.postJsonParams(url+LOGINPATH,jsonParams));
            if(jsonObject.getString("status").equals("SUCCESS")){
                JSONObject token = jsonObject.getJSONObject("result");
                userinfo.put("token",token.getString("ref"));
                JSONObject userJ = JSONObject.parseObject(OkHttpUtil.getUserInfo(url+USERINFO,token.getString("acc")));
                if(userJ.getString("status").equals("SUCCESS")){
                    JSONObject userRe = userJ.getJSONObject("result");
                    userinfo.put("id",userRe.getString("id"));
                    userinfo.put("username",userRe.getString("username"));
                    if(null!= userRe.getString("displayName")){
                        userinfo.put("displayName",userRe.getString("displayName"));
                    }else{
                        userinfo.put("displayName",userRe.getString("在线用户"));
                    }
                }
            }
        }catch (Exception e){
        }
        return userinfo;
    }

    public static void downLoadTask(String taskId ,String url){

    }
}
